<%- title "Setting up a GitHub webhook" %>
<%- description "Setting up a GitHub webook to update scripts on Greasy Fork automatically." %>

<p>A GitHub webhook connected with Greasy Fork makes it so any push to your GitHub repository automatically updates your scripts on Greasy Fork in a matter of minutes.</p>

<p>To use this feature, you must have scripts on Greasy Fork set up to sync from GitHub. You can add new scripts by <%= link_to 'importing new scripts into Greasy Fork', import_start_path%>, or you can set previously posted scripts to sync by accessing the "Sync" tab from the script's page. Here's the GitHub-syncing scripts you have so far:</p>

<% if @github_scripts.empty? %>
	<p><i>(None)</i></p>
<% else %>
	<ul>
		<% @github_scripts.each do |s| %>
			<li><%=link_to s.name, s%> - <%=s.script_sync_type.name.downcase%> syncing from <%=link_to s.sync_identifier, s.sync_identifier%></li>
		<% end %>
	</ul>
<% end %>

<p>To set up the webhook on GitHub's side, access to your GitHub repository and go to Settings, Webhooks &amp; Services, Add webhook, then enter the data below. You can set up multiple repositories with the same info.</p>
<dl>
	<dt>Payload URL</dt>
	<dd><%=user_webhook_url(@user)%></dd>
	<dt>Content type</dt>
	<dd>application/json</dd>
	<dt>Secret</dt>
	<dd>
		<%=form_tag do |f|%>
			<% if @user.webhook_secret.nil? %>
				<input type="submit" value="Generate">
			<% else %>
				<textarea cols="64" rows="2"><%=@user.webhook_secret%></textarea> <input type="submit" value="Regenerate">
			<% end %>
		<%end%>
	</dd>
	<dt>Which events would you like to trigger this webhook?</dt>
	<dd>Just the push event.</dd>
	<dt>Active</dt>
	<dd>(Checked)</dd>
</dl>

<p>After you set up the webhook, GitHub will send a ping to Greasy Fork. If this ping is successful, then you've set things up correctly. Your scripts will continue to show a sync type of "Automatic" or "Manual" until the first push happens, and then they'll be set to "Webhook".</p>
